package com.bysj.yqsht.service.impl;

import com.bysj.yqsht.bean.Wages;
import com.bysj.yqsht.bean.WagesExample;
import com.bysj.yqsht.bean.extend.WagesExtend;
import com.bysj.yqsht.dao.WagesMapper;
import com.bysj.yqsht.dao.extend.WagesExtendMapper;
import com.bysj.yqsht.service.IWagesService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class IWagesServiceImpl implements IWagesService {
    @Resource
    private WagesMapper wagesMapper;
    @Resource
    private WagesExtendMapper wagesExtendMapper;
    @Override
    public List<Wages> findAll() {
        WagesExample Example = new WagesExample();
        return wagesMapper.selectByExample(Example);
    }

    @Override
    public List<WagesExtend> findWithAll(int pageNum, int limit) {
        PageHelper.startPage(pageNum,limit);
        WagesExample example = new WagesExample();
        List<WagesExtend> list1 = wagesExtendMapper.findWithAll();
        PageInfo<WagesExtend> data = new PageInfo<WagesExtend>(list1);
        List<WagesExtend> list = data.getList();
        return list;
    }

    @Override
    public List<WagesExtend> findWithAllBy(String status, Long teacherId) {
        return wagesExtendMapper.findWithAllBy(status,teacherId);
    }

    @Override
    public void saveOrUopdate(Wages wages) {
        if(wages.getId() != null){
            wagesMapper.updateByPrimaryKey(wages);
        }else {
            wagesMapper.insert(wages);
        }

    }

    @Override
    public void deleteById(long id) {
      wagesMapper.deleteByPrimaryKey(id);

    }
}
